%# Copyright (c) 2021-2024 Huawei Device Co., Ltd.
%# Licensed under the Apache License, Version 2.0 (the "License");
%# you may not use this file except in compliance with the License.
%# You may obtain a copy of the License at
%#
%# http://www.apache.org/licenses/LICENSE-2.0
%#
%# Unless required by applicable law or agreed to in writing, software
%# distributed under the License is distributed on an "AS IS" BASIS,
%# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%# See the License for the specific language governing permissions and
%# limitations under the License.
%#
%
% require_relative 'Array_code'

% Data::get_lambda_data.each { |lambda_args_params|
%   lambda_params_num, lambda_args, lambda_params = lambda_args_params
/**
 * Creates a new `Array` object and populates
 * it with the results of calling a provided function on every element in `this` instance of `Array` class.
 *
 * @param fn mapping function, applied to each element of an array.
 *
 * @returns `Array` instance, constructed from `this` and given function.
 */
<%= access_public %> map<%= map_generic %>(<%= this_arg %>fn: (value: <%= el_type %><%= lambda_params %>) => <%= mapped_type %>): <%= array_of_type.(mapped_type) %> {
    const len = <%= this_len_int %>;
    let res = <%= make_buffer.('len', mapped_type) %>;
    for (let i = 0; i < len; i++) {
        res[i] = fn(<%= get_unsafe.(this, 'i') %><%= lambda_args %>);
    }
    return <%= from_buffer.('res', mapped_type) %>;
}
% }
